import type { IGetPhoneNumber, ILoginData, ILoginRes, IUserInfo } from './types';
import { defHttp } from '@/utils/http';
import { excSocial, social, root } from '../apiRoot';
import { IsOfficialAccountEnum } from '@/enums/loginEnum';

const Api = {
  phoneNumber: social + 'phoneNumber/mini_yjr',
  login: excSocial + 'login/mini_yjr',
  logOut: root + 'login/exit',
  userInfo: social + 'getUserInfo',
  getWebAuthUrl: root + 'wechatAuth/getWebAuthUrl',
};

/**
 * 登录
 * @export
 * @param {ILoginData} data
 */
export function login(data: ILoginData) {
  return defHttp.post<ILoginRes>({
    url: Api.login,
    data,
  });
}

/**
 * 退出登录
 */
export function logOut() {
  return defHttp.post({
    url: Api.logOut,
  });
}

/**
 * 获取用户信息
 * @export
 */
export function userInfo(token: string) {
  return defHttp.post<IUserInfo>({
    url: Api.userInfo,
    header: { token },
  });
}

/**
 * 获取微信手机号
 * @export
 * @param {IGetPhoneNumber} data
 * @return {*}  {(Promise<number | string>)}
 */
export function getPhoneNumber(
  data: IGetPhoneNumber,
): Promise<{ isOfficialAccount: IsOfficialAccountEnum, mobile: string }> {
  return defHttp.post({
    url: Api.phoneNumber,
    data,
    // header,
  });
}

/**
 * @description 获取公众号授权链接
 * @date 12/12/2022
 * @export
 */
export function getWebAuthUrl() {
  return defHttp.get<string>({
    url: Api.getWebAuthUrl,
  });
}
